//
//  CLSettingPWViewController.m
//  CareLink
//
//  Created by w on 16/8/18.
//  Copyright © 2016年 Seven Team. All rights reserved.

/**
 *  登录密码界面2
 *  
 */
#import "CLSettingPWViewController.h"
#import "CLSettingHeaderViewController.h"
@interface CLSettingPWViewController ()
{
    //视图
    UIView *bgView;
    //密码文本
    UITextField *passward;
}
//记录发送短信的电话号码字符串
@property (nonatomic, copy) NSString *keyStr;
@end

@implementation CLSettingPWViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"";
    self.view.backgroundColor = [UIColor colorWithRed:240/255.0f green:240/255.0f blue:240/255.0f alpha:1];
    UIBarButtonItem *addBtn = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(clickaddBtn)];
    [addBtn setImage:[UIImage imageNamed:@"goback_back_orange_on"]];
    [addBtn setImageInsets:UIEdgeInsetsMake(0, -15, 0, 15)];
    addBtn.tintColor = [UIColor colorWithRed:248/255.0f green:144/255.0f blue:34/255.0f alpha:1];
    [self.navigationItem setLeftBarButtonItem:addBtn];
    
    [self createTextFields];
}
#pragma mark 内容
-(void)createTextFields
{
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(30, 75, self.view.frame.size.width-90, 30)];
    label.text = @"请设置密码";
    label.textColor = [UIColor grayColor];
    label.textAlignment = UITextAlignmentLeft;
    label.font = [UIFont systemFontOfSize:13];
    [self.view addSubview:label];
    
    CGRect frame = [UIScreen mainScreen].bounds;
    bgView=[[UIView alloc]initWithFrame:CGRectMake(10, 110, frame.size.width-20, 50)];
    bgView.layer.cornerRadius = 3.0;
    bgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bgView];
    
    passward = [self createTextFielfFrame:CGRectMake(100, 10, 200, 30) font:[UIFont systemFontOfSize:14] placeholder:@"6-20位字母或数字"];
    passward.clearButtonMode = UITextFieldViewModeWhileEditing;
    passward.secureTextEntry = YES;
    
    UIImageView* userImageView = [self createImageViewFrame:CGRectMake(20, 10, 25, 25) imageName:@"注册-手机号" color:nil];
//    UILabel *phonelabel=[[UILabel alloc]initWithFrame:CGRectMake(20, 12, 50, 25)];
//    phonelabel.text=@"密码";
//    phonelabel.textColor=[UIColor blackColor];
//    phonelabel.textAlignment=UITextAlignmentLeft;
//    phonelabel.font=[UIFont systemFontOfSize:14];
    
    
    UIButton *landBtn = [self createButtonFrame:CGRectMake(10, bgView.frame.size.height+bgView.frame.origin.y+30,self.view.frame.size.width-20, 37) backImageName:nil title:@"下一步" titleColor:[UIColor whiteColor]  font:[UIFont systemFontOfSize:17] target:self action:@selector(landClick)];
    landBtn.backgroundColor = [UIColor colorWithRed:8 / 255.0 green:65 / 255.0 blue:130 / 255.0 alpha:0.8];
    landBtn.layer.cornerRadius = 5.0f;
    
    [bgView addSubview:passward];
    [bgView addSubview:userImageView];
    [self.view addSubview:landBtn];
}


#pragma mark 跳转到设置密码界面3
-(void)landClick
{
    //commit验证短信验证码是否正确
        self.keyStr = [[NSUserDefaults standardUserDefaults] objectForKey:@"tel"];
                [[NSUserDefaults standardUserDefaults] setObject:passward.text forKey:KpassWord];
    if (self.number == 0) {
        [self.navigationController pushViewController:[[CLSettingHeaderViewController alloc] init] animated:YES];
    }
    if (self.number == 2) {
        [self.navigationController pushViewController:[[CLSettingHeaderViewController alloc] init] animated:YES];
    }
    
}

-(UITextField *)createTextFielfFrame:(CGRect)frame font:(UIFont *)font placeholder:(NSString *)placeholder
{
    UITextField *textField = [[UITextField alloc]initWithFrame:frame];
    
    textField.font = font;
    
    textField.textColor = [UIColor grayColor];
    
    textField.borderStyle = UITextBorderStyleNone;
    
    textField.placeholder = placeholder;
    
    return textField;
}

-(UIImageView *)createImageViewFrame:(CGRect)frame imageName:(NSString *)imageName color:(UIColor *)color
{
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:frame];
    
    if (imageName)
    {
        imageView.image = [UIImage imageNamed:imageName];
    }
    if (color)
    {
        imageView.backgroundColor = color;
    }
    
    return imageView;
}

-(UIButton *)createButtonFrame:(CGRect)frame backImageName:(NSString *)imageName title:(NSString *)title titleColor:(UIColor *)color font:(UIFont *)font target:(id)target action:(SEL)action
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = frame;
    if (imageName)
    {
        [btn setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    }
    
    if (font)
    {
        btn.titleLabel.font = font;
    }
    
    if (title)
    {
        [btn setTitle:title forState:UIControlStateNormal];
    }
    if (color)
    {
        [btn setTitleColor:color forState:UIControlStateNormal];
    }
    if (target&&action)
    {
        [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    }
    return btn;
}

-(void)clickaddBtn
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
